<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
</head>
<body style="font-family: '微软雅黑'">
	<div id="tb" style="padding: 5px; height: auto">
		<div>

			<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-add"
				onclick="add();">添加</a> <span
				class="toolbar-item dialog-tool-separator"></span> <a href="#"
				class="easyui-linkbutton" plain="true" iconCls="icon-remove"
				onclick="del()">删除</a> <span
				class="toolbar-item dialog-tool-separator"></span> <a href="#"
				class="easyui-linkbutton" plain="true" iconCls="icon-edit"
				onclick="upd()">修改</a> <span
				class="toolbar-item dialog-tool-separator"></span> <a href="#"
				class="easyui-linkbutton" plain="true"
				iconCls="icon-hamburg-advertising"
				onclick="screenFull('<%=path%>/maerialview/weathern')">天气投影/预览</a> <span
				class="toolbar-item dialog-tool-separator"></span> <a href="#"
				class="easyui-linkbutton" plain="true" iconCls="icon-standard-cog"
				onclick="setting()">设置</a>

		</div>
	</div>
	<table id="dg"></table>

	<div id="dlg"></div>
	<div id="icon_dlg"></div>

	<script type="text/javascript">
var dg;
var d;
$(function(){   
	dg=$('#dg').datagrid({    
	method: "get",
    url:'<%=path%>/system/Area/getareaList', 
    cache: false, 
    fit : true,
	fitColumns : true,
	border : false,
	idField : 'id',
		striped:true,
	pagination:true,
	rownumbers:true,
	pageNumber:1,
	pageSize : 20,
	pageList : [ 10, 20, 30, 40, 50 ],
	singleSelect:true,
    columns:[[    
        {field:'id',title:'id',hidden:true},    
        {field:'areaCode',title:'区域编码',sortable:true,width:100},    
        {field:'areaName',title:'区域名称',sortable:true,width:100}
    ]],
    headerContextMenu: [
        {
            text: "冻结该列", disabled: function (e, field) { return dg.datagrid("getColumnFields", true).contains(field); },
            handler: function (e, field) { dg.datagrid("freezeColumn", field); }
        },
        {
            text: "取消冻结该列", disabled: function (e, field) { return dg.datagrid("getColumnFields", false).contains(field); },
            handler: function (e, field) { dg.datagrid("unfreezeColumn", field); }
        }
    ],
    enableHeaderClickMenu: true,
    enableHeaderContextMenu: true,
    enableRowContextMenu: false,
    toolbar:'#tb'
	});
});

// 格式化时间
Date.prototype.format = function (format) {  
    var o = {  
        "M+": this.getMonth() + 1, // month  
        "d+": this.getDate(), // day  
        "h+": this.getHours(), // hour  
        "m+": this.getMinutes(), // minute  
        "s+": this.getSeconds(), // second  
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter  
        "S": this.getMilliseconds()  
        // millisecond  
    }  
    if (/(y+)/.test(format))  
        format = format.replace(RegExp.$1, (this.getFullYear() + "")  
            .substr(4 - RegExp.$1.length));  
    for (var k in o)  
        if (new RegExp("(" + k + ")").test(format))  
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
    return format;  
}  
function formatDatebox(value) {  
    if (value == null || value == '') {  
        return '';  
    }  
    var dt;  
    if (value instanceof Date) {  
        dt = value;  
    } else {  
        dt = new Date(value);  
    }  
  
    return dt.format("yyyy-MM-dd"); //扩展的Date的format方法(上述插件实现)  
}  
function subB() {
	var fileV = $('#excelIm').val();
	if(typeof(fileV)!='undefined' && fileV != '') {
		$('#subF').submit();
		$(":button").attr("disabled", true);
	}else {
		layer.msg("未选择导入文件！");
	}
}

var msg="${result}";
if(typeof(msg)!='undefined'&&msg!='') {
	layer.msg(msg);
}
	

//弹窗增加
function add() {
	//父级权限
	var row = dg.treegrid('getSelected');
	if(row){
		parentPermId=row.id;
	}
	
	d=$('#dlg').dialog({    
	    title: '新增数据',    
	    width: 450,    
	    height: 320,    
	    closed: false,    
	    cache: false,
	    maximizable:true,
	    resizable:true,
	    href:'<%=path%>/system/Area/areacreate',
	    modal: true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit();
			}
		},{
			text:'取消',
			handler:function(){
					d.panel('close');
				}
		}]
	});
}

//删除
function del(){
	var row = dg.treegrid('getSelected');
	if(rowIsNull(row)) return;
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"<%=path%>/system/Area/deletearea/"+row.id,
				success: function(data){
					if(successTip(data,dg))
			    		dg.treegrid('reload');
				}
			});
			//dg.datagrid('reload'); //grid移除一行,不需要再刷新
		} 
	});

}

//修改
function upd(){
	var row = dg.treegrid('getSelected');
	if(rowIsNull(row)) return;
	//父级权限
	parentPermId=row.pid;
	d=$("#dlg").dialog({   
	    title: '修改数据',    
	    width: 450,    
	    height: 320,    
	    href:'<%=path%>/system/Area/updatearea/'+row.id,
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit();
			}
		},{
			text:'取消',
			handler:function(){
					d.panel('close');
				}
		}]
	});

}

function setting(){
	d=$("#dlg").dialog({   
	    title: '配置',    
	    width: 450,    
	    height: 320,    
	    href:'<%=path%>/setting/index/11',
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#mainform").submit();
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});
		}
	</script>
</body>
</html>